package com.guoyansoft.model.service.impl;

import com.guoyansoft.config.R;
import com.guoyansoft.model.dao.PendingOrdersDao;
import com.guoyansoft.model.pojo.Customer;
import com.guoyansoft.model.pojo.District;
import com.guoyansoft.model.pojo.PendingOrders;
import com.guoyansoft.model.pojo.Yardman;
import com.guoyansoft.model.service.PendingOrdersService;
import com.guoyansoft.model.service.YardmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 刘耀诚
 * 待处理订单service实现类
 */
@Service
public class PendingOrdersServiceImpl implements PendingOrdersService {
    @Autowired
    private PendingOrdersDao pendingOrdersDao;
    @Autowired
    private YardmanService yardmanService;
    @Override
    public R save(PendingOrders pendingOrders) {
        int row = pendingOrdersDao.insert(pendingOrders);
        return row>0?R.suc():R.fail();
    }

    @Override
    public R modify(PendingOrders pendingOrders) {
        int row = pendingOrdersDao.update(pendingOrders);
        return row>0?R.suc():R.fail();
    }

    @Override
    public R drop(String[] id) {
        int row = pendingOrdersDao.delete(id);
        return row>0?R.suc():R.fail();
    }

    @Override
    public R queryById(String id) {
        PendingOrders pendingOrders = pendingOrdersDao.selectById(id);
        return R.suc(pendingOrders);
    }

    @Override
    public R queryByPage(Map<String, Object> params) {
        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByPage(params);
        Long total = pendingOrdersDao.selectTotal(params);
        return R.suc(total,pendingOrders);
    }

    @Override
    public R queryByYardmanPage(Map<String, Object> map) {
       Integer yardmanId = (Integer) map.get("yardmanId");
        R r = yardmanService.queryAddress(yardmanId);
         List<District> districts= (List<District>) r.getData();
            String[] district=new String[districts.size()];
        for (int i = 0; i < districts.size(); i++) {
            String str="";
           str= districts.get(i).getProvince()+","+districts.get(i).getCity()+","+districts.get(i).getDistrict();
           district[i]=str;
            System.out.println(district[i]);
        }
           map.put("district",district);

        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByYardmanByPage(map);

        Long total = pendingOrdersDao.selectTotal(map);
        return R.suc(total,pendingOrders);
    }

    @Override
    public R queryByCourierPage(Map<String, Object> map) {
        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByCourierByPage(map);
        Long total = pendingOrdersDao.selectTotal(map);
        return R.suc(total,pendingOrders);
    }

    @Override
    public R modifyState(Map<String, Object> map) {
        int state = pendingOrdersDao.updateState(map);
        return state>0?R.suc():R.fail();
    }

    @Override
    public R queryByCourierPendingOrders(Map<String, Object> map) {
        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByCourierPendingOrders(map);
        return R.suc(pendingOrders);
    }

    @Override
    public R queryByCustomer(Customer customer) {
        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByCustomer(customer);
        return R.suc(pendingOrders);
    }

//    @Override
//    public R queryByStoreName(Map<String, Object> params) {
//        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByStoreName(params);
//        Long total = pendingOrdersDao.selectTotal(params);
//        return R.suc(total,pendingOrders);
//    }
//
//    @Override
//    public R queryByGoodsName(Map<String, Object> params) {
//        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByGoodsName(params);
//        Long total = pendingOrdersDao.selectTotal(params);
//        return R.suc(total,pendingOrders);
//    }
//
//    @Override
//    public R queryByState(Map<String, Object> params) {
//        List<PendingOrders> pendingOrders = pendingOrdersDao.selectByState(params);
//        Long total = pendingOrdersDao.selectTotal(params);
//        return R.suc(total,pendingOrders);
//    }
}
